﻿using Newtonsoft.Json.Linq;
using OpenCvSharp;
using RantAIOCR.Common;
using System.Windows;

namespace RantLEDOCR
{
    /// <summary>
    /// Setting.xaml 的交互逻辑
    /// </summary>
    public partial class Setting : System.Windows.Window
    {
        MainWindow mainWindow;
        public Setting()
        {
            InitializeComponent();
            mainWindow = (MainWindow)App.Current.MainWindow;
            textbox1.Text = mainWindow.width1.ToString();
            textbox2.Text = mainWindow.width2.ToString();
            textbox3.Text = mainWindow.threshold1.ToString();
            textbox4.Text = mainWindow.threshold2.ToString();
            textbox5.Text = mainWindow.delta1.ToString();
            textbox6.Text = mainWindow.delta2.ToString();
            string s= AppConfigurtaionServices.Configuration["debug"];
            if (s != null && s == "1")
                IsDebug.IsChecked = true;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.width1 = int.Parse(textbox1.Text);
            mainWindow.width2 = int.Parse(textbox2.Text);
            mainWindow.threshold1 = int.Parse(textbox3.Text);
            mainWindow.threshold2 = int.Parse(textbox4.Text);
            mainWindow.delta1 = int.Parse(textbox5.Text);
            mainWindow.delta2 = int.Parse(textbox6.Text);
            var t1 = new Peramter { Threshold = mainWindow.threshold1, Width = mainWindow.width1, Delta=mainWindow.delta1 };
            var t2 = new Peramter { Threshold = mainWindow.threshold2, Width = mainWindow.width2, Delta = mainWindow.delta2 };
            Peramter[] peramters = { t1, t2 };


            AppConfigurtaionServices.updateObject("Paramters", peramters);


            if (IsDebug.IsChecked == true)
            {
                AppConfigurtaionServices.updateitem("Debug", "1");
            }
            else
                AppConfigurtaionServices.updateitem("Debug", "0");
            this.Close();
        }
    }
}
